import request from '@/utils/request-new'
import type { Response, PageDataList } from '@/utils/type'

// 获取年份
export function getIndicatorYear(): Promise<Response<string[]>> {
  return request({
    url: '/screen/index/common/getIndexYear',
    method: 'get'
  })
}

// 获取指标列表
export function getIndicatorList(params: any): Promise<Response<PageDataList<any>>> {
  return request({
    url: '/screen/index/common/query',
    method: 'get',
    params
  })
}

// 新增或更新指标
export function addOrUpdateIndicator(data: any): Promise<Response<any>> {
  return request({
    url: '/screen/index/common/addOrUpdate',
    method: 'post',
    data
  })
}

// 删除指标
export function deleteIndicator(params: any): Promise<Response<any>> {
  return request({
    url: '/screen/index/common/delete',
    method: 'post',
    params
  })
} 

// 复制
export function copyIndicator(params: any): Promise<Response<any>> {
  return request({
    url: '/screen/index/common/copy',
    method: 'get',
    params
  })
}

// 新增或更新评价标准
export function addJudge(data: any): Promise<Response<any>> {
  return request({
    url: '/screen/index/common/addJudge',
    method: 'post',
    data
  })
}

// 获取操作日志
export function getLogList(params: any): Promise<Response<PageDataList<any>>> {
  return request({
    url: '/log/index/query',
    method: 'get',
    params
  })
}

// 获取所有数据源
export function getAllDataSources(): Promise<Response<any[]>> {
  return request({
    url: '/screen/index/coreRunDataSource/getAll',
    method: 'get'
  })
}

// 获取数据源的表信息
export function getDataSourceTables(pkid: string): Promise<Response<any[]>> {
  return request({
    url: `/screen/index/coreRunDataSource/tables/${pkid}`,
    method: 'get'
  })
}

// 查询SQL
export function querySQL(pkid: string, sql: string): Promise<Response<any[]>> {
  return request({
    url: `/screen/index/coreRunDataSource/query/${pkid}`,
    method: 'post',
    data: { sql }
  })
}

// 添加核心运行语句
export function addCoreRun(data: { coreRun: string; coreRunDataSource: string; indexId: string }): Promise<Response<any>> {
  return request({
    url: '/screen/index/common/addCoreRun',
    method: 'post',
    data
  })
}

export function getLayerFieldsByLayerName(data: any): Promise<Response<any[]>> {
  return request({
    url: `/screen/index/common/getShowDictListByLayerName`,
    method: 'post',
    data
  })
}

export function addLayerFieldsByLayerName(data: any): Promise<Response<any[]>> {
  return request({
    url: `/screen/index/common/addMapInfo`,
    method: 'post',
    data
  })
}

// 批量执行sql
export function executeMutiSql(data: any): Promise<Response<any[]>> {
  return request({
    url: `/screen/index/common/executeSqlUpdateIndexValue`,
    method: 'post',
    data
  })
}



